from typing import *


class Solution:
    def alternatingSubarray(self, nums: List[int]) -> int:
        ans, cnt = 0, 0
        for i in range(1, len(nums)):
            if nums[i] - nums[i - 1] == 1:
                if cnt & 1 == 1:
                    cnt += 1
                else:
                    cnt = 2
            elif nums[i] - nums[i - 1] == -1 and cnt > 0 and cnt & 1 == 0:
                cnt += 1
            else:
                cnt = 0
            ans = max(ans, cnt)
        return ans if ans > 0 else -1


s = Solution()
print(s.alternatingSubarray([6, 12, 2, 3, 8, 9, 10, 10, 2, 1]))
